using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

namespace org.ngwt.user.server.rpc
{
    public static class JavaDotNetClassTrans
    {

        private static NameValueCollection JAVA_TO_NET_TYPE_NAME = new NameValueCollection();
        private static NameValueCollection NET_TO_JAVA_TYPE_NAME = new NameValueCollection();

        static JavaDotNetClassTrans()
        {
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.String", "System.String");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Boolean", "System.Boolean");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Byte", "System.Byte");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Character", "System.Char");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Double", "System.Double");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Float", "System.Single");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Integer", "System.Int32");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Long", "System.Int64");
            JAVA_TO_NET_TYPE_NAME.Add("java.lang.Short", "System.Int16");
            JAVA_TO_NET_TYPE_NAME.Add("java.util.ArrayList", "System.Collections.ArrayList");
            JAVA_TO_NET_TYPE_NAME.Add("java.util.Date", "System.DateTime");

            JAVA_TO_NET_TYPE_NAME.Add("Z", "System.Boolean");
            JAVA_TO_NET_TYPE_NAME.Add("B", "System.Byte");
            JAVA_TO_NET_TYPE_NAME.Add("C", "System.Char");
            JAVA_TO_NET_TYPE_NAME.Add("D", "System.Double");
            JAVA_TO_NET_TYPE_NAME.Add("F", "System.Single");
            JAVA_TO_NET_TYPE_NAME.Add("I", "System.Int32");
            JAVA_TO_NET_TYPE_NAME.Add("J", "System.Int64");
            JAVA_TO_NET_TYPE_NAME.Add("S", "System.Int16");

            JAVA_TO_NET_TYPE_NAME.Add("[Z", "System.Boolean[]");
            JAVA_TO_NET_TYPE_NAME.Add("[B", "System.Byte[]");
            JAVA_TO_NET_TYPE_NAME.Add("[C", "System.Char[]");
            JAVA_TO_NET_TYPE_NAME.Add("[D", "System.Double[]");
            JAVA_TO_NET_TYPE_NAME.Add("[F", "System.Single[]");
            JAVA_TO_NET_TYPE_NAME.Add("[I", "System.Int32[]");
            JAVA_TO_NET_TYPE_NAME.Add("[J", "System.Int64[]");
            JAVA_TO_NET_TYPE_NAME.Add("[S", "System.Int16[]");
            JAVA_TO_NET_TYPE_NAME.Add("[Ljava.lang.String;", "System.String[]");

            NET_TO_JAVA_TYPE_NAME.Add("System.String", "java.lang.String");
            NET_TO_JAVA_TYPE_NAME.Add("System.Boolean","java.lang.Boolean");
            NET_TO_JAVA_TYPE_NAME.Add("System.Byte","java.lang.Byte");
            NET_TO_JAVA_TYPE_NAME.Add("System.Char","java.lang.Character");
            NET_TO_JAVA_TYPE_NAME.Add("System.Double","java.lang.Double");
            NET_TO_JAVA_TYPE_NAME.Add("System.Single","java.lang.Float");
            NET_TO_JAVA_TYPE_NAME.Add("System.Int32","java.lang.Integer");
            NET_TO_JAVA_TYPE_NAME.Add("System.Int64","java.lang.Long");
            NET_TO_JAVA_TYPE_NAME.Add("System.Int16","java.lang.Short");
            NET_TO_JAVA_TYPE_NAME.Add("System.Collections.ArrayList", "java.util.ArrayList");
            NET_TO_JAVA_TYPE_NAME.Add("System.DateTime", "java.util.Date");

            NET_TO_JAVA_TYPE_NAME.Add( "System.Boolean[]","[Z");
            NET_TO_JAVA_TYPE_NAME.Add( "System.Byte[]","[B");
            NET_TO_JAVA_TYPE_NAME.Add( "System.Char[]","[C");
            NET_TO_JAVA_TYPE_NAME.Add( "System.Double[]","[D");
            NET_TO_JAVA_TYPE_NAME.Add("System.Single[]","[F");
            NET_TO_JAVA_TYPE_NAME.Add( "System.Int32[]","[I");
            NET_TO_JAVA_TYPE_NAME.Add( "System.Int64[]","[J");
            NET_TO_JAVA_TYPE_NAME.Add( "System.Int16[]","[S");
            NET_TO_JAVA_TYPE_NAME.Add( "System.String[]","[Ljava.lang.String;");
        }

        public static string JavaToNet(string javaClassName)
        {
            string doNetClassName = JAVA_TO_NET_TYPE_NAME[javaClassName];
            if (doNetClassName != null)
                return doNetClassName.Replace("com.google.gwt", "org.ngwt");
            else
                return javaClassName.Replace("com.google.gwt", "org.ngwt");
        }

        public static string NetToJava(string doNetClassName)
        {
            string javaClassName = NET_TO_JAVA_TYPE_NAME[doNetClassName];
            if (javaClassName != null)
                return javaClassName;
            else
                return doNetClassName;
        }
        public static string NetToJava(Type type)
        {
            return NetToJava(type.FullName);
        }


    }
}
